<?php


namespace App\Http\Model;


use Illuminate\Support\Facades\DB;


class RoomImageCheck extends Base
{
    protected $tableRoomImageCheck = 'room_image_check';
    protected $tablePrimaryKey = 'id';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    public function CUDTable($data = [], $type = 'insert', $id = 0)
    {
        switch ($type) {
            case 'insert':
                $ret = DB::table($this->tableRoomImageCheck)->insertGetId($data);
                break;
            case 'update':
                $ret = DB::table($this->tableRoomImageCheck)->where([$this->tablePrimaryKey => $id])->update($data);
                break;
            case 'delete':
                $ret = DB::table($this->tableRoomImageCheck)->where([$this->tablePrimaryKey => $id])->delete();
                break;
            default:
                $ret = false;
                break;
        }
        return $ret;
    }

    public function getImgList($room_id, $page = 1, $limit = 10)
    {
        $result = DB::table($this->tableRoomImageCheck)
            ->where(['room_id'=>$room_id ,'status'=>1]) //0 未审核 1 审核通过 2 审核不通过
            ->orderBy( 'created_at', 'desc')
            ->offset($limit * ($page - 1))
            ->limit($limit)
            ->get(['id' ,'image']);
        return self::objToArray($result);
    }

    public function getInfo($id){
        $result = DB::table($this->tableRoomImageCheck)->find($id);
        return self::objToArray($result);
    }
}